﻿using UnityEngine;

public class Text3DController : MonoBehaviour
{
    private GameObject _mainCamera;
    int updateCount = 30;
    int i = 0;

    // Start is called before the first frame update
    private void Start()
    {
        _mainCamera = GameObject.FindWithTag("MainCamera");
    }

    // Update is called once per frame
    private void Update()
    {
        i++;

        if (i > updateCount)
        {
            i = 0;
            _mainCamera = GameObject.FindWithTag("MainCamera");
        }

        //物体始终面向摄像机
        var rotation = Quaternion.LookRotation(_mainCamera.transform.TransformVector(Vector3.forward),
                    _mainCamera.transform.TransformVector(Vector3.up));
        rotation = new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w);
        gameObject.transform.rotation = rotation;
    }
}